import { createRouter, createWebHashHistory } from 'vue-router'

// 统一在这里声明所有路由
const routes = [
    {
        path: '/', // 路由地址
        name: 'Layout',
        component: () => import('@/layouts/Layout.vue'), // 对应组件
        meta: { // meta 信息
            title: '首页' // 页面标题
        },
        children: [
            {
                path: '',
                name: 'Home',
                component: () => import('@/views/HomeView.vue'),
                meta: {
                    title: '主页'
                }
            },
            {
                path: '/ai',
                name: 'AI',
                component: () => import('@/views/ai/Index.vue'),
                meta: {
                    title: 'AI聊天'
                },
                redirect: { name: 'NewChat' }, // 添加重定向
                children: [
                    {
                        path: '',
                        name: 'NewChat',
                        component: () => import('@/views/ai/NewChat.vue'),
                        meta: {
                            title: '创建AI对话'
                        }
                    },
                    {
                        path: 'chat/:chatId',
                        name: 'Chat',
                        component: () => import('@/views/ai/Chat.vue'),
                        meta: {
                            title: 'AI对话'
                        }
                    },
                    {
                        path: 'chat/role',
                        name: 'Role',
                        component: () => import('@/views/ai/Role.vue'),
                        meta: {
                            title: 'AI 角色'
                        }
                    },
                    {
                        path: 'chat/toolbox',
                        name: 'Toolbox',
                        component: () => import('@/views/ai/Toolbox.vue'),
                        meta: {
                            title: 'AI 工具'
                        }
                    },
                    {
                        path: 'chat/role/:chatId',
                        name: 'RoleChat',
                        component: () => import('@/views/ai/RoleChat.vue'),
                        meta: {
                            title: 'AI 角色对话'
                        }
                    },
                ]
            },
            {
                path: '/friendLink',
                name: 'FriendLink',
                component: () => import('@/views/FriendLinkView.vue'),
                meta: {
                    title: '友链'
                },
            },
            {
                path: '/about',
                name: 'About',
                component: () => import('@/views/AboutView.vue'),
                meta: {
                    title: '关于'
                },
            }
        ]
    },
]

// 创建路由
const router = createRouter({
    // 指定路由模式，hash 模式指的是 URL 的路径是通过 hash 符号（#）进行标识
    history: createWebHashHistory(),
    // routes: routes 的缩写
    routes, 
})

// ES6 模块导出语句，它用于将 router 对象导出，以便其他文件可以导入和使用这个对象
export default router